# Set working directory
setwd("")

# Plot weighting functions for scoring rules

# Axis
c <- seq(from=0.01,to=0.99,by=0.01)

# Weighting as a function of c, for scoring rules in Table 1
ls <- (1/(c*(1-c)))
ls <- ls/sum(ls)
qs <- rep(1,length(c))/length(c)
ss <- (1-2*c+2*c^2)^(-1.5)
ss <- ss/sum(ss)
rs <- 1/c
rs <- rs/sum(rs)
ds <- 1/(1-c)
ds <- ds/sum(ds)
bs <- (c*(1-c))^(-1.5)
bs <- bs/sum(bs)

# Colors
cols <- rep(c("gray70", "gray40", "gray20"), each = 2)
ltys <- rep(c(1, 2, 3), 2)
lwds <- c(3, 3, 6, 3, 3, 3)

# Make pdf
pdf("weightingfunctions.pdf", family = "Bookman")
# Plot weightings against c
matplot(x = c, y = cbind(ls,qs,ss,bs,rs,ds), type="l", ylim=c(0,0.05), ylab=expression(nu(c)), xlab=expression(c), lwd = lwds,
        col = cols, lty = ltys, bty = "n")
# Annotate curves
text(c(0.5, 0.865, 0.5, 0.5, 1-0.865, 0.35), c(0.016, 0.02, 0.009, 0.0002, 0.02, 0.02), labels = c("Spherical", "As2", "Brier", "Boosting", "As1", "Log"))
segments(0.2, 0.006, 0.35, 0.019)
dev.off()